package com.supermap.startup;

import com.supermap.data.Scenes;
import com.supermap.data.Workspace;
import com.supermap.data.WorkspaceConnectionInfo;
import com.supermap.data.WorkspaceType;
import com.supermap.desktop.core.Application;
import com.supermap.desktop.core.Interface.IFormScene;
import com.supermap.desktop.core.enums.WindowType;
import com.supermap.desktop.core.utilties.FormUtilities;
import com.supermap.desktop.core.utilties.ThreadUtilties;

import javax.swing.*;

public class cStartup {
    public static void main(String[] args) {
        ThreadUtilties.executeAfterDesktopVisible(() -> {
            // 打开默认工作空间
            Application activeApplication = Application.getActiveApplication();
            Workspace workspace = activeApplication.getWorkspace();
            WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo();
            workspaceConnectionInfo.setServer("sampleData/3D/CBDDataset/CBD.smwu");
            workspaceConnectionInfo.setType(WorkspaceType.SMWU);
            workspace.open(workspaceConnectionInfo);

            // 默认打开当前工作空间中的第一个场景
            Scenes scenes = workspace.getScenes();
            String sceneName = scenes.get(0);
            SwingUtilities.invokeLater(() -> {
                IFormScene sceneForm = (IFormScene) FormUtilities.fireNewWindowEvent(WindowType.SCENE, sceneName);
                sceneForm.openScene(sceneName);
            });
        });

        if (!Application.getActiveApplication().initialize()) {
            System.exit(0);
        }
    }
}
